<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css"
          th:href="@{/bootstrap/css/bootstrap.min.css}"/>
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}">
    </script>
    <!-- jquery-validator 做校验的-->
    <script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- md5.js -->
    <script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>
<form name="loginForm" id="loginForm" method="post" style="width:50%; margin:0
auto">
    <h2 style="text-align:center; margin-bottom: 20px">用户注册</h2>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入手机号码</label>
            <div class="col-md-5">
                <input id="mobile" name="mobile" class="form-control"
                       type="text" placeholder="手机号码" required="true"
                       minlength="11" maxlength="11"/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入密码</label>
            <div class="col-md-5">
                <input id="password" name="password" class="form-control"
                       type="password" placeholder="密码"
                       required="true" minlength="6" maxlength="16"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请再次输入密码</label>
            <div class="col-md-5">
                <input id="confirmPassword" name="confirmPassword" class="form-control"
                       type="password" placeholder="确认密码"
                       required="true" minlength="6" maxlength="16"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入昵称</label>
            <div class="col-md-5">
                <input id="nickname" name="nickname" class="form-control"
                       type="text" placeholder="昵称" required="true"/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入身份证号</label>
            <div class="col-md-5">
                <input id="identifyNumber" name="identifyNumber" class="form-control"
                       type="text" placeholder="身份证号" required="true"
                       minlength="18" maxlength="18"/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入真实姓名</label>
            <div class="col-md-5">
                <input id="realName" name="realName" class="form-control"
                       type="text" placeholder="真实姓名" required="true"/>
            </div>
            <div class="col-md-1">
            </div>
        </div>
    </div>
    <div class="form-group">
        <div class="row">
            <label class="form-label col-md-4">请输入工作状态</label>
            <div class="form-group">
                <form method="post">
                    <input type="radio" name="state" value="1" id="incumbency"/>在职
                    <input type="radio" name="state" value="2" id="resignation"/>不在职
                </form>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="reset" onclick="reset()">重置</button>
        </div>
        <div class="col-md-5">
            <button class="btn btn-primary btn-block" type="button"
                    onclick="regist()">注册</button>
        </div>
    </div>

</form>
</body>
<script>

    function regist(){
        g_showLoading();
        var inputPass = $("#password").val();
        var confirmPassword = $("#confirmPassword").val();
        if(inputPass == confirmPassword){
            var salt = g_passsword_salt;
            var str = "" + salt.charAt(0) + salt.charAt(2) + inputPass +
                salt.charAt(5) + salt.charAt(4);
            var password = md5(str);
        }else {
            layer.msg("两次密码不一致");
            return;
        }
        if($("input[name='state']:checked").val()==1){
            //选择在职
            var workStatus = 1;
        }else {
            var workStatus = 0;
        }

        console.log(inputPass);
        console.log(confirmPassword);
        console.log(password);
        console.log($("#nickname").val());
        console.log($("#identifyNumber").val());
        console.log($("#realName").val());
        console.log(workStatus);

        $.ajax({
            url: "/login/doRegist",
            type: "POST",
            data: {
                mobile: $("#mobile").val(),
                password: password,
                nickname: $("#nickname").val(),
                identifyNumber: $("#identifyNumber").val(),
                realName: $("#realName").val(),
                workStatus: workStatus
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 200) {
                    layer.msg("注册成功");
                    window.location.href='/login/toLogin';
                } else {
                    layer.msg(data.message);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
    function doLogin() {
        g_showLoading();
        var inputPass = $("#password").val();
        var salt = g_passsword_salt;
        var str = "" + salt.charAt(0) + salt.charAt(2) + inputPass +
            salt.charAt(5) + salt.charAt(4);
        var password = md5(str);
        $.ajax({
            url: "/login/doLogin",
            type: "POST",
            data: {
                mobile: $("#mobile").val(),
                password: password
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 200) {
                    layer.msg("登录成功");
                    window.location.href='/goods/toList';
                } else {
                    layer.msg(data.message);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
    function  reset(){
        document.getElementById('loginForm').reset();
    }
</script>
</html>